<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>等级名</td>
                    <td>
                        <input type="text" v-model="Level.LevelName">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();
import axios from 'axios';

const Level=reactive({
    LevelName:""
})
    


const add=()=>{
    //验证有效性
    if(Level.LevelName==""){
        alert('等级名不能为空');
        return;
    }
    //发送网络请求
    axios({
        method:"post",
        url:"/api/User/AddLevel",
        data:Level
    })
    .then(res=>{
        //判断
        console.log(res);
        if(res.data==-1){
            alert('等级名重复');
            return;
        }
        else if(res.data>0){
            alert('添加成功');
            router.push('/showLevel');
        }
        else{
            alert('添加失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>